Skip to content

fix(selfHosted): align worker lifecycle behavior - #14

Merged
ark-hand[bot] merged 1 commit into
mainfrom
sync/handfix-71cc0eae26
Sep 2, 2026
Merged

fix(selfHosted): align worker lifecycle behavior#14
ark-hand[bot] merged 1 commit into
mainfrom
sync/handfix-71cc0eae26

Conversation

@ark-hand

@ark-hand ark-hand Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Hand-written change from the internal SDK repository — not produced by make vendor.

  • source subject: fix(selfHosted): align worker lifecycle behavior
  • reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.

简述

补齐 Python self-hosted worker 的工具超时配置,并对齐 Anthropic 的长连接和工具执行生命周期语义。

修改前

  • EnvironmentWorkerOptions 无法直接配置单次工具执行超时。
  • timeout 只进入 ToolContext,非协作 custom tool 如果不主动检查 cancel_event,仍会阻塞 SessionToolRunner。
  • SSE timeout 处理不清晰,误设为 None 会让静默断流无法及时退出。
  • 新字段若插入 dataclass 中间会改变既有位置参数含义。

修改后

  • EnvironmentWorkerOptions 增加 tool_timeout_seconds,并透传 SessionToolRunner 和 ToolContext。
  • 正值覆盖 ToolContext;None、0、负值保留用户 ToolContext 或 120s 默认值。
  • SessionToolRunner 在 daemon thread 中执行工具,并在外层强制 deadline;超时后立即返回 error result,不等待忽略取消的工具,对齐 Anthropic anyio.fail_after 与 abandon_on_cancel 行为。
  • 超时或 worker 停止时设置组合 cancel_event,配合型工具可及时释放进程和资源。
  • SSE 保留 30s 读空闲 timeout;httpx 不设置整次 stream 总时长限制,静默断流仍可触发重连。
  • WorkPoller 文档明确 AutoStop 是串行 iterator 语义;并发 dispatch 必须关闭并自行维护 heartbeat 和 stop。
  • 新字段放在 dataclass 尾部,保持原位置参数顺序。

边界

  • 非协作工具的后台线程可能继续运行到自身返回,但结果会被丢弃;这是 Anthropic abandon-on-cancel 的相同行为,工具仍应响应 cancel_event 释放资源。
  • 本 MR 不修改 SIGTERM 时 force-stop 行为,不实现 work 迁移、release 或 requeue。

验证

  • Python 全量单测:52 passed
  • Ruff 全量检查通过
  • wheel 和 sdist 构建成功
  • test/run.sh --sdk:Go、Python、Java 真实 STG worker 3/3 通过
  • test/run.sh --all:真实 STG 全量默认套件通过,Docker 和直接 work-contract 用例按独立模式开关跳过

See merge request: !92

Sync-Source-Commit: 71cc0eae2668d0f5dc0fa57d1f450ef63d40d910
Hand-Written-Reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.
Release-Version: 0.4.0

Created by ark-hand.

## 简述

补齐 Python self-hosted worker 的工具超时配置,并对齐 Anthropic 的长连接和工具执行生命周期语义。

## 修改前

- EnvironmentWorkerOptions 无法直接配置单次工具执行超时。
- timeout 只进入 ToolContext,非协作 custom tool 如果不主动检查 cancel_event,仍会阻塞 SessionToolRunner。
- SSE timeout 处理不清晰,误设为 None 会让静默断流无法及时退出。
- 新字段若插入 dataclass 中间会改变既有位置参数含义。

## 修改后

- EnvironmentWorkerOptions 增加 tool_timeout_seconds,并透传 SessionToolRunner 和 ToolContext。
- 正值覆盖 ToolContext;None、0、负值保留用户 ToolContext 或 120s 默认值。
- SessionToolRunner 在 daemon thread 中执行工具,并在外层强制 deadline;超时后立即返回 error result,不等待忽略取消的工具,对齐 Anthropic anyio.fail_after 与 abandon_on_cancel 行为。
- 超时或 worker 停止时设置组合 cancel_event,配合型工具可及时释放进程和资源。
- SSE 保留 30s 读空闲 timeout;httpx 不设置整次 stream 总时长限制,静默断流仍可触发重连。
- WorkPoller 文档明确 AutoStop 是串行 iterator 语义;并发 dispatch 必须关闭并自行维护 heartbeat 和 stop。
- 新字段放在 dataclass 尾部,保持原位置参数顺序。

## 边界

- 非协作工具的后台线程可能继续运行到自身返回,但结果会被丢弃;这是 Anthropic abandon-on-cancel 的相同行为,工具仍应响应 cancel_event 释放资源。
- 本 MR 不修改 SIGTERM 时 force-stop 行为,不实现 work 迁移、release 或 requeue。

## 验证

- Python 全量单测:52 passed
- Ruff 全量检查通过
- wheel 和 sdist 构建成功
- test/run.sh --sdk:Go、Python、Java 真实 STG worker 3/3 通过
- test/run.sh --all:真实 STG 全量默认套件通过,Docker 和直接 work-contract 用例按独立模式开关跳过

See merge request: !92

Sync-Source-Commit: 71cc0eae2668d0f5dc0fa57d1f450ef63d40d910
Hand-Written-Reason: Hand-written self-hosted worker lifecycle alignment; not produced by ark-apis generation.
Release-Version: 0.4.0
@ark-hand
ark-hand Bot merged commit ba68b5b into main Sep 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants